<template>
  <div class="tabContent">
    <ul>
      <li v-for="(tab,index) in tabs"
          :key="index"
          @click="toggle(index,tab.view)"
          :class="{active:active==index}">
        <span class="tableft">
          <span class="span"
                :class="logoBgs[index]"></span>
        </span>
        <span>{{tab.type}}</span>
      </li>
    </ul>
    <!--:is实现多个组件实现同一个挂载点-->
    <component :is="currentView"></component>
  </div>
</template>

<script>
import tab1 from './select01.vue'
import tab2 from './select02.vue'
import tab3 from './select03.vue'
import tab4 from './select04.vue'
export default {
  name: 'app',
  data () {
    return {
      active: 0,
      currentView: 'tab1',
      tabs: [
        {
          type: '雾化',
          view: 'tab1'
        },
        {
          type: '血糖',
          view: 'tab2'
        },
        {
          type: '血压',
          view: 'tab3'
        },
        {
          type: '体温',
          view: 'tab4'
        }
      ],
      logoBgs: ['bg1', 'bg2', 'bg3', 'bg4']
    }
  },
  methods: {
    toggle (i, v) {
      this.active = i
      this.currentView = v
    }
  },
  components: {
    tab1,
    tab2,
    tab3,
    tab4
  }
}
</script>

<style lang="stylus" scoped>
@import '../../../static/css/comm.css';

.tabContent {
  height: 4.5rem;
  margin-bottom: 0.3rem;
  background-color: #fff;
  border-radius: 0.15rem;
  box-shadow: 0 0 0.1rem #e9edf2;
  display: flex;
}

ul {
  width: 1.4rem;
  background-color: #29b8ff;
  border-top-left-radius: 0.15rem;
  border-bottom-left-radius: 0.15rem;
  padding: 0.2rem 0 0 0.1rem;

  li {
    width: 1.4rem;
    height: 0.5rem;
    color: #fff;
    text-align: center;
    line-height: 0.5rem;
    font-size: 0.28rem;
    span{
      vertical-align: middle;
    }
  }
}

ul li.active {
  background: rgba(255, 255, 255, 0.18);
  border-top-left-radius: 0.1rem;
  border-bottom-left-radius: 0.1rem;
}

.tableft {
  display: inline-block;
  width: 0.3rem;
}

.span {
  display: inline-block;
}

.bg1 {
  background-image: url('../../../static/images/wuhua.png');
  width: 0.1rem;
  height: 0.3rem;
}

.bg2 {
  background-image: url('../../../static/images/xuetang.png');
  width: 0.2rem;
  height: 0.23rem;
}

.bg3 {
  background-image: url('../../../static/images/xueya.png');
  width: 0.12rem;
  height: 0.3rem;
}

.bg4 {
  background-image: url('../../../static/images/tiwen.png');
  width: 0.25rem;
  height: 0.25rem;
}
</style>
